import axios from 'axios';
import { BASEURL } from '../config/index';

const service = axios.create({
  timeout: 60000,
});

service.interceptors.request.use((config) => {
  return config
}, (err) => {
  return Promise.reject(err)
})


service.interceptors.response.use((response) => {
  return Promise.resolve(response.data)
}, (error) => {

  return Promise.reject(error);
})

// 返回一个函数，可以在操作前进行其他操作
export default (option: AxiosReq.Req) => {
  const { url, method, data, baseURL = BASEURL } = option;

  return service({
    url,
    method,
    data,
    baseURL
  } as any)
}